﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TI_4_Limonade_Fabriek.Database;
using TI_4_Limonade_Fabriek.Model;

namespace TI_4_Limonade_Fabriek
{
    public partial class InsertUserScreen : Form
    {
        UserDBController udbc;
        public InsertUserScreen()
        {
            InitializeComponent();
            udbc = new UserDBController();
        }

        private void GebruikerInvoeren_Load(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnSaveUser_Click(object sender, EventArgs e)
        {
            if (tbGebruikersnaam.Text != "" && mtbWachtwoord.Text != "" && cbGebruikersRol.SelectedIndex >= 0)
            {
                User user = new User();
                user.Username = tbGebruikersnaam.Text;
                user.Password = user.HashPassword(mtbWachtwoord.Text);
                user.UserRole = cbGebruikersRol.SelectedIndex;

                udbc.CreateUser(user);

                MessageBox.Show("Gebruiker toegevoegd.");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Voer geldige gegevens in.");
            }

        }

        private void cbShowPassword_CheckedChanged(object sender, EventArgs e)
        {
            if (cbShowPassword.Checked)
            {
                mtbWachtwoord.PasswordChar = char.Parse("\0");
            }
            else
            {
                mtbWachtwoord.PasswordChar = char.Parse("*");
            }
        }
    }
}
